package com.best.oasis.settlement.biz.facade.base
{
	import com.best.oasis.settlement.common.error.ErrorCode;
	import com.best.oasis.settlement.common.model.ModelLocator;
	
	import flash.events.Event;
	
	import mx.controls.Alert;
	import mx.core.FlexGlobals;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;

	/**
	 * rpc调用的SuperResponder，替代import com.best.oasis.settlement.biz.facade.base.SuperResponder。
	 * 这里面添加了统一的rpc异常处理：如果会话超时，直接把界面切换到登录界面
	 * @author BL00064
	 */
	public class SuperResponder extends Responder
	{
		private var resultFunc:Function;
		private var faultFunc:Function;
		
		public function SuperResponder(result:Function, fault:Function)
		{
			resultFunc = result;
			faultFunc = fault;
			super(onResult, onFault);
		}
		public function onResult(event : * = null ):void{
			resultFunc(event);
		}
		public function onFault(event : * = null ):void{
			var tEvent:FaultEvent = event as FaultEvent;
			trace(tEvent.fault);
			if(tEvent.fault.faultString == ErrorCode.NOT_LOGINED){
				//TODO
				//open a login popup dialog
				
				ModelLocator.getInstance().mainContentViewStackSelectedIndex = 0;
				ModelLocator.getInstance().authMsg = '会话超时，请重新登录。';
				FlexGlobals.topLevelApplication.systemManager.dispatchEvent(new Event("Systemlogout"));
				trace('not logined');
			}else if(tEvent.fault.faultCode == "Channel.Call.Failed"){
				Alert.show("连接服务器超时或服务器无响应.");
				trace('连接服务器超时或服务器无响应');
			}else{
				faultFunc(event);
			}
		}
	}
}